<?php
namespace app\admin\model;
use think\Model;
use app\admin\model\Areas;
use app\admin\model\Networks;
use app\admin\model\Users;
class Orders extends Model
{
	public static function add($network_id,$user_id,$type=1){
		$order['create_time'] = time();
		$order['action_time'] = date('Y-m-d H:i:s',time());
		$order['status'] = 1;
		$order['auther'] = $user_id;
		$order['type'] = $type;
		$network = new Networks;
		$row = $network->where('id',$network_id)->field('*,local_cloud_id as locallabel,endcloudid as endclou,type as locatlabeladdress,status as statuslabel,type as typelabel,appro_time as approtime,endtype as endlabeladdress')->find();
		$order['title'] = $row['name'];
		$order['user_id'] = $row['user_id'];
		$order['value'] = serialize($row->toArray());
		$order['total'] = $row['total'];
		$order['country'] = $row['currency'];
		$order['sn'] = $row['sn'];
		$order['email'] = Users::getEmail($row['user_id']);
		return self::insert($order);
	}
	public function getTypelabelAttr($value){
		switch (intval($value)) {
			case 2:
				$value = lang('Adjust');
				break;
			case 3:
				$value = lang('Delete');
				break;
			case 4:
				$value = lang('_Renewal');
				break;
			default:
				$value = lang('Opening');
				break;
		}
		return $value ;
	}
}